﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MobileIdeas.MobileTasks.SDK.DAL.DataAccess
{
    public class UserDAO : DataAccessObject
    {
        #region Get

        public List<User> GetCompanyUsers(int companyId, int? areaId)
        {
            using (var entities = this.EntityContext)
            {
                var query = from e in entities.user
                            where (e.company.companyId == companyId)
                            select e;

                return query.ToList();
            }
        }

        public List<User> GetClientUsers(int clientId)
        {
            using (var entities = this.EntityContext)
            {
                var query = from e in entities.user
                            where e.client.clientId == clientId
                            select e;

                return query.ToList();
            }
        }

        public User GetUser(string username, string password, int companyId)
        {
            using (var entities = this.EntityContext)
            {
                return entities.user.FirstOrDefault(e => 
                    e.userName.CompareTo(username) == 0 &&
                    e.password.CompareTo(password) == 0 &&
                    e.company.companyId == companyId);
            }
        }

        #endregion

        #region Add

        public void AddUser(User user)
        {
            using (var entities = this.EntityContext)
            {
                entities.AddTouser(user);
                entities.SaveChanges();
            }
        }

        #endregion

        #region Modify

        public void ModifyUser(User user)
        {

            
        }

        #endregion


    }
}
